using IM.Easy.Infrastructure.Query;
using Microsoft.AspNetCore.Mvc;
using IM.Easy.SystemServices.Dtos;
using IM.Easy.SystemServices.IServices;
using IM.Easy.Entity.System;
using IM.Easy.Core.Attributes;

namespace IM.Easy.Api.Controllers.System
{
    /// <summary>
    /// SvgIconsController 控制器
    /// </summary>
    [Route("system/svgIcon")]
    public class SvgIconsController : ControllerBase
    {
        private readonly ISvgIconsService _service;

        /// <summary>
        /// 构造函数，注入服务
        /// </summary>
        /// <param name="service">服务接口</param>
        public SvgIconsController(ISvgIconsService service)
        {
            _service = service;
        }

        /// <summary>
        /// 获取所有SvgIcons对象
        /// </summary>
        /// <returns>返回SvgIcons列表</returns>
        [Api(AllowAnonymous = true, Name = "获取个性化图标", Required = true)]
        [HttpGet]
        public PageResponse<SvgIcons> GetList([FromQuery] SvgIconsQueryDto query)
        {
            return _service.GetPageList(query);
        }

        /// <summary>
        /// 根据ID获取SvgIcons对象
        /// </summary>
        /// <param name="id">对象的ID</param>
        /// <returns>返回指定的SvgIcons对象</returns>
        [Api(AllowAnonymous = true, Name = "获取个性化图标")]
        [HttpGet("{id}")]
        public SvgIcons GetById([FromRoute] long id)
        {
            var result = _service.GetById(id);
            return result ?? throw new KeyNotFoundException($"未找到ID为 {id} 的SvgIcons对象。");
        }

        /// <summary>
        /// 创建新的SvgIcons对象
        /// </summary>
        /// <param name="entity">要创建的SvgIcons对象</param>
        /// <returns>返回创建后的SvgIcons对象</returns>
        [Api(AllowAnonymous = false, Name = "添加个性化图标", Perm = "svgicon:add")]
        [HttpPost]
        public SvgIcons Create([FromBody] SvgIcons entity)
        {
            _service.Create(entity);
            return entity; // 直接返回创建的实体
        }

        /// <summary>
        /// 更新现有的SvgIcons对象
        /// </summary>
        /// <param name="id">对象的ID</param>
        /// <param name="entity">更新后的SvgIcons对象</param>
        [Api(AllowAnonymous = false, Name = "更新个性化图标", Perm = "svgicon:put")]
        [HttpPut]
        public void Update([FromBody] SvgIcons entity)
        {
            _service.Update(entity);
        }

        /// <summary>
        /// 批量删除SvgIcons对象
        /// </summary>
        /// <param name="ids">对象的IDS</param>
        [Api(AllowAnonymous = false, Name = "删除个性化图标", Perm = "svgicon:del")]
        [HttpDelete]
        public void Delete([FromBody] long[] ids)
        {
            _service.Delete(ids);
        }

    }
}
